<!DOCTYPE html>
<html>
<head>
    <script src="../../../resources/js-test.js"></script>
    <script>
        if (window.testRunner) {
            testRunner.dumpAsText();
            testRunner.waitUntilDone();
        }

        function buildInlineSharedWorker() {
            var script = document.getElementById('workerCode').innerText;
            var blob = new Blob([script], {type: 'text/javascript'});
            var worker = new SharedWorker(URL.createObjectURL(blob));
            worker.port.start();
            worker.port.postMessage({cmd: 'connect', id: "host"});

            worker.port.addEventListener('message', function (e) {
                if (e.data.done)
                    setTimeout(finishJSTest, 0);
            });

            return worker;
        }
    </script>
</head>
<body>
    <!-- This script's body will be used to build a Blob URL to use as a Worker. -->
    <script id="workerCode" type="text/plain">
        console.log("log");
        console.log(typeof console.log);
        console.log(console.log.toString());
        console.error("error");
        console.warn("warn");
        console.info("info");
        console.debug("debug");
        console.count("count");
        console.time("time");
        /*
        // FIXME(slightlyoff): these aren't getting logged properly from here!
        console.timeEnd("time");
        console.assert(true);
        console.assert(false);
        */
        self.addEventListener("connect", function (e) {
            var port = e.ports[0];
            port.postMessage({ done: true });
        });
    </script>
    <script>
        window.jsTestIsAsync = true;
        description("This tests that 'console.log' and friends function correctly from workers.");
        buildInlineSharedWorker();
    </script>
</body>
</html>
